<?php
namespace Admin\Controller;
use Mcit\Page;
class InterfaceparamController extends BaseController {

    //首页
    public function index(){


            $sql = "select * from char_param_config";

            $count = count(M()->query($sql));
 
            vendor('Mcit.Sys.Page');
            $Page = new Page($count, 20);
            $pageView = $Page->show();
            $this->assign('pageView', $pageView); //发送分页
            $nowPage = isset($_GET['page']) ? $_GET['page'] * 20 - 20 : 0;
 
            
            
            $sql1 = "select * from char_param_config limit {$nowPage},{$Page->listRows}";
   

            
      
            
            $char_param_config = M()->query($sql1);
            //分页结束
 
        //var_dump($char_param_config);
 
        $this->assign('char_param_config',$char_param_config);
        $this->display();
    }


    public function add(){

        if(IS_POST){
            $param_name=$_POST['param_name'];
            $param_value=$_POST['param_value'];
            $desciption=$_POST['description'];
            
            $sql="insert into char_param_config (param_name,param_value,description) values ('{$param_name}','{$param_value}','{$desciption}')";

            $result = M()->query($sql);
           
            //echo M()->getLastSql();
            
            if($result > 0){
                $this->redirect("Interfaceparam/index");
            }else{
                $this->error("操作失败，请重试！");
            }
        }


    }

    //查看电桩详细信息
    public function detail(){
        if(IS_GET){
            $id=$_GET['id'];
            $sql="select * from char_param_config where id='{$id}'";
            $data = M()->query($sql);
            
            foreach ($data as $k=>$v){
                $one=$v;
                break;
            }
            $this->data = $one;
        }
        $this->display();
    }

    public function update(){
        if(IS_GET){
            $id=$_GET['id'];
            $sql = "select * from char_param_config where id='{$id}'";
            
            $data = M()->query($sql);
            
            foreach ($data as $k=>$v){
                $one=$v;
                break;
            }
            $this->paramone=$one;
            $this->display();
        }
        
        
        if(IS_POST){
            $id=$_POST['id'];
            $param_name=$_POST['param_name'];
            $param_value=$_POST['param_value'];
            $desciption=$_POST['description'];
        
            $sql="update char_param_config set param_name='{$param_name}',param_value='{$param_value}',description='{$desciption}' where id='{$id}'";
        
            $result = M()->query($sql);
             
            //echo M()->getLastSql();
        
            if($result > 0){
                $this->redirect("Interfaceparam/index");
            }else{
                $this->error("操作失败，请重试！");
            }
        }
    }
  
    public function  del(){
        if(IS_GET){
            $id=$_GET['id'];
            $sql="delete from char_param_config where id='{$id}'";
            $result = M()->query($sql);
        
            if($result > 0){
                $this->redirect("Interfaceparam/index");
            }else{
                $this->error("操作失败，请重试！");
            }
        }
    }
}